{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_excel('区分度检验数据.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Q13的量表题数据\n",
    "group13A = data['13.以下作为您使用AI对话助手动机的符合程度—A.名声大噪']\n",
    "group13B = data['B.服务良好']\n",
    "group13C = data['C.学术专业']\n",
    "group13D = data['D.随便看看']\n",
    "group13E = data['E.娱乐休闲']\n",
    "group13F = data['F.猎奇心理']\n",
    "group13Name = ['A.名声大噪','B.服务良好','C.学术专业','D.随便看看','E.娱乐休闲','F.猎奇心理']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Q14的量表题数据\n",
    "group14A = data['14.请您为下列AI对话助手的特征进行打分—A.全天候可用性']\n",
    "group14B = data['B.回答全面性']\n",
    "group14C = data['C.回答准确性']\n",
    "group14D = data['D.回答高效性']\n",
    "group14E = data['E.回答可理解性']\n",
    "group14F = data['F.回答所用知识的时效性']\n",
    "group14G = data['G.多语言性(能够接收和回答多种语言)']\n",
    "group14H = data['H.多端联结性(可多端同步使用)']\n",
    "group14I = data['I.多模态交互性(能够接收多种类型的文件)']\n",
    "group14J = data['J.个性化服务性']\n",
    "group14K = data['K.安全性隐私性']\n",
    "group14K.head()\n",
    "group14Name = ['A.全天候可用性','B.回答全面性','C.回答准确性','D.回答高效性','E.回答可理解性','F.回答所用知识的时效性','G.多语言性(能够接收和回答多种语言)','H.多端联结性(可多端同步使用)','I.多模态交互性(能够接收多种类型的文件)','J.个性化服务性','K.安全性隐私性']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Q15的量表题数据\n",
    "group15A = data['15.请您为AI对话助手的功能或服务打分—A.了解该对话助手的各方面信息，如性能、特色等']\n",
    "group15B = data['B.专业智能体的使用或定制']\n",
    "group15C = data['C.下载对话助手的移动端、PC端']\n",
    "group15D = data['D.搜索与推理模型']\n",
    "group15E = data['E.聊天信息的共享']\n",
    "group15F = data['F.查看升级版的功能与价格']\n",
    "group15G = data['G.本地部署']\n",
    "group15Name = ['A.了解该对话助手的各方面信息，如性能、特色等','B.专业智能体的使用或定制','C.下载对话助手的移动端、PC端','D.搜索与推理模型','E.聊天信息的共享','F.查看升级版的功能与价格','G.本地部署']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "KMO检验结果： 0.9615171628833018\n"
     ]
    }
   ],
   "source": [
    "#进行KMO检验\n",
    "from factor_analyzer.factor_analyzer import calculate_kmo\n",
    "groups_df = pd.concat([group13A, group13B, group13C, group13D, group13E, group13F, group14A, group14B, group14C, group14D, group14E, group14F, group14G, group14H, group14I, group14J, group14K, group15A, group15B, group15C, group15D, group15E, group15F, group15G], axis=1)\n",
    "kmo_all, kmo_model = calculate_kmo(groups_df)\n",
    "print('KMO检验结果：', kmo_model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "巴特利特检验结果：近似卡方 2580.480631707664\n",
      "自由度 276\n",
      "P值 0.0\n"
     ]
    }
   ],
   "source": [
    "#进行巴特利特检验，输出近似卡方，自由度df与P值\n",
    "from factor_analyzer.factor_analyzer import calculate_bartlett_sphericity\n",
    "chi_square_value, p_value = calculate_bartlett_sphericity(groups_df)\n",
    "p = groups_df.shape[1]  # 变量数\n",
    "df = (p * (p - 1)) // 2  # 自由度\n",
    "print('巴特利特检验结果：近似卡方', chi_square_value)\n",
    "print('自由度', df)\n",
    "print('P值', p_value)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
